from hanchlogger import logger
import openpyxl
import hanchxl


class infoConfig(object):
    def __init__(self):
        self.DirectoryConfig = {}

    def get_config_info(self, file_config=''):
        if file_config != '':
            # 打开 “配置信息” 文件
            logger.debug('打开 配置信息 文件：{}'.format(file_config))
            bookConfiguration = openpyxl.load_workbook(file_config, data_only=True)
            sheetConfig = bookConfiguration.active
            maxRowConfig = sheetConfig.max_row
            maxColConfig = sheetConfig.max_column
            logger.debug('配置信息.xlsx -------行数：{}行    列数：{}列'.format(maxRowConfig, maxColConfig))
            indexConfig = hanchxl.get_col_index(sheetConfig, '配置项')
            indexConfigValue = hanchxl.get_col_index(sheetConfig, '属性值')
            for rowIndex in range(2, maxRowConfig + 1):
                valueConfig = '{}'.format(sheetConfig.cell(rowIndex, indexConfig).value).strip()
                valueConfigvalue = '{}'.format(sheetConfig.cell(rowIndex, indexConfigValue).value).strip()
                if valueConfig != '' and valueConfigvalue != '':
                    self.DirectoryConfig[valueConfig] = valueConfigvalue

        return self.DirectoryConfig


